import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;


public class Ejercicio2 {
	
	public void leerArchivo() throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(new File("Tp2Ej2.in")));
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Tp2Ej2.out")));
		String [] linea = br.readLine().trim().split("\\s+");
		while(Integer.parseInt(linea[0]) != -1 && Integer.parseInt(linea[1]) != -1) {
			
			Integer marea = Integer.parseInt(linea[0]);
			Integer cantVallas = Integer.parseInt(linea[1]);
			List<Valla> listaValla = new LinkedList<Valla>();
			
			for (int i = 0; i < cantVallas; i++) {
				Valla v = new Valla(br.readLine());
				listaValla.add(v);
			}
			
			IslaTurbia it = new IslaTurbia(marea, listaValla);
			bw.write( it.operacionSalvatajeDeDroga() + "" );
			bw.newLine();
			linea = br.readLine().trim().split("\\s+");
	
		}
		br.close();
		bw.close();
	}
	
	public static void main(String[] args) {
		try {
			Ejercicio2 ej = new Ejercicio2();
			ej.leerArchivo();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
